package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type MilkCouponApi struct {
}

var milkCouponService = service.ServiceGroupApp.AutoCodeServiceGroup.MilkCouponService


// CreateMilkCoupon 创建MilkCoupon
// @Tags MilkCoupon
// @Summary 创建MilkCoupon
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.MilkCoupon true "创建MilkCoupon"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /milkCoupon/createMilkCoupon [post]
func (milkCouponApi *MilkCouponApi) CreateMilkCoupon(c *gin.Context) {
	var milkCoupon autocode.MilkCoupon
	_ = c.ShouldBindJSON(&milkCoupon)
	if err := milkCouponService.CreateMilkCoupon(milkCoupon); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteMilkCoupon 删除MilkCoupon
// @Tags MilkCoupon
// @Summary 删除MilkCoupon
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.MilkCoupon true "删除MilkCoupon"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /milkCoupon/deleteMilkCoupon [delete]
func (milkCouponApi *MilkCouponApi) DeleteMilkCoupon(c *gin.Context) {
	var milkCoupon autocode.MilkCoupon
	_ = c.ShouldBindJSON(&milkCoupon)
	if err := milkCouponService.DeleteMilkCoupon(milkCoupon); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteMilkCouponByIds 批量删除MilkCoupon
// @Tags MilkCoupon
// @Summary 批量删除MilkCoupon
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除MilkCoupon"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /milkCoupon/deleteMilkCouponByIds [delete]
func (milkCouponApi *MilkCouponApi) DeleteMilkCouponByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := milkCouponService.DeleteMilkCouponByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateMilkCoupon 更新MilkCoupon
// @Tags MilkCoupon
// @Summary 更新MilkCoupon
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.MilkCoupon true "更新MilkCoupon"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /milkCoupon/updateMilkCoupon [put]
func (milkCouponApi *MilkCouponApi) UpdateMilkCoupon(c *gin.Context) {
	var milkCoupon autocode.MilkCoupon
	_ = c.ShouldBindJSON(&milkCoupon)
	if err := milkCouponService.UpdateMilkCoupon(milkCoupon); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindMilkCoupon 用id查询MilkCoupon
// @Tags MilkCoupon
// @Summary 用id查询MilkCoupon
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.MilkCoupon true "用id查询MilkCoupon"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /milkCoupon/findMilkCoupon [get]
func (milkCouponApi *MilkCouponApi) FindMilkCoupon(c *gin.Context) {
	var milkCoupon autocode.MilkCoupon
	_ = c.ShouldBindQuery(&milkCoupon)
	if err, remilkCoupon := milkCouponService.GetMilkCoupon(milkCoupon.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"remilkCoupon": remilkCoupon}, c)
	}
}

// GetMilkCouponList 分页获取MilkCoupon列表
// @Tags MilkCoupon
// @Summary 分页获取MilkCoupon列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.MilkCouponSearch true "分页获取MilkCoupon列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /milkCoupon/getMilkCouponList [get]
func (milkCouponApi *MilkCouponApi) GetMilkCouponList(c *gin.Context) {
	var pageInfo autocodeReq.MilkCouponSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := milkCouponService.GetMilkCouponInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
